<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>6_1_1-2-组件生命周期挂载和卸载动作</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="Application">
    <sub-com v-if="show"> </sub-com>
    <button @click="changeShow">测试</button>
  </div>

  <script>
    const sub = {
      beforeCreate() {
        console.log("组件即将创建前");
      },

      created() {
        console.log("组件创建完成");
      },

      beforeMount() {
        console.log("组件即将挂载前");
      },

      updated() {
        console.log("组件挂载完成");
      },

      beforeMount() {
        console.log("组件即将被卸载前调用");
      },

      unmounted() {
        console.log("组件被卸载后调用");
      },
    };

    const App = Vue.createApp({
      data() {
        return {
          show: false,
        };
      },
      methods: {
        changeShow() {
          this.show = !this.show;
        },
      },
    });
    App.component("sub-com", sub);

    App.mount("#Application"); //将Vue组件绑定到页面上id为Application的元素上。
  </script>
</body>

</html>